package com.hbnu.object;

/**
 * this关键字
 *
 * @author kittychen
 * @date 2025-09-10 下午 3:35
 */
public class Person {
    private String username;

    public Person() {
        this("张三");   // 注意点：this调用构造方法时，必须放在构造方法的第一行
        System.out.println("无参构造方法");
    }

    public Person(String username) {
        this.username = username;
    }

    public void method(String username) {
        System.out.println(username);   // 输出局部变量username，即参数username
        System.out.println(this.username);  // 输出成员变量username
    }

    public void method2() {
//        method("李四");
        System.out.println("调用method方法");
        this.method("李四");
    }

    public static void main(String[] args) {
        Person person1 = new Person();
        Person person2 = new Person();

        person1.method2();
        person2.method2();

    }
}
